import request from '@/utils/request'

// 查询设施管理列表
export function listFacilities(query) {
  return request({
    url: '/rooms/Facilities/list',
    method: 'get',
    params: query
  })
}


// 根据厂房编号查询设施管理列表
export function getFacilitiesByRoomCode(roomCode, data) {
  return request({
    url: `/rooms/Facilities/listByRoomCode/${roomCode}`, // 路径参数roomCode
    method: 'post', // 对应后端@PostMapping
    data: data // 请求体参数，对应后端@RequestBody
  })
}

// 查询设施管理详细
export function getFacilities(id) {
  return request({
    url: '/rooms/Facilities/' + id,
    method: 'get'
  })
}

/**
 * 根据厂房编号新增设施
 * @param {Object} facilities 设施信息对象（不需要包含isDelete、locationRoomCode、createdAt、facilityCode字段）
 * @param {string} roomCode 厂房编码（如R20250728538）
 * @returns {Promise} 请求Promise
 */
export function addFacilitiesByRoomCode(facilities, roomCode) {
  return request({
    url: '/rooms/Facilities/newFacilities/' + roomCode,  // 尝试使用字符串拼接而非模板字符串
    method: 'post',
    data: facilities
  })
}

// 修改设施管理
export function updateFacilities(data) {
  return request({
    url: '/rooms/Facilities',
    method: 'put',
    data: data
  })
}

// 删除设施管理
export function delFacilities(id) {
  return request({
    url: '/rooms/Facilities/' + id,
    method: 'delete'
  })
}


// 根据房间编码查询设备信息
export function findFacilitiesByRoomCode(roomCode) {
  return request({
    url: '/rooms/Facilities/findByRoomCode/' + roomCode,
    method: 'post'
  })
}

